package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
@Slf4j
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     *
     * @return
     */
    @ApiOperation(value = "查询所有护理计划")
    @GetMapping
    public ResponseResult<List<NursingPlanVo>> queryAllNursingPlan() {

        List<NursingPlanVo> vo = nursingPlanService.queryAllNursingPlan();
        return success(vo);
    }

    /**
     * 分页条件查询
     */
    @ApiOperation(value = "条件分页查询")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> queryPage(@ApiParam(value = "护理等级名称条件")
                                                                 String name,
                                                                 @RequestParam(required = false, defaultValue = "1")
                                                                 @ApiParam(value = "当前页码", required = true)
                                                                 Integer pageNum,
                                                                 @ApiParam(value = "每页大小", required = true)
                                                                 @RequestParam(required = false, defaultValue = "10")
                                                                 Integer pageSize,
                                                                 @ApiParam(value = "状态条件")
                                                                 Integer status) {
        PageResponse<NursingPlanVo> voPageResponse = nursingPlanService.queryPage(name, pageNum, pageSize, status);
        return success(voPageResponse);
    }

    /**
     * 新增护理计划
     */
    @PostMapping
    @ApiOperation(value = "新增护理计划")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto dto) {

        nursingPlanService.addNursingPlan(dto);
        return success();
    }

    @ApiOperation(value = "根据id查询护理计划")
    @GetMapping("{id}")
    public ResponseResult<NursingProjectPlanVo> queryById(@PathVariable Integer id) {

        NursingPlanVo vo = nursingPlanService.queryById(id);
        return success(vo);
    }

    /**
     * 修改护理计划
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "修改护理计划信息")
    @PutMapping("{id}")
    public ResponseResult modifyNursingPlan(@RequestBody NursingPlanDto dto) {

        nursingPlanService.modifyNursingPlan(dto);
        return success();
    }
    /**
     * 删除护理计划
     */
    @ApiOperation(value = "删除护理计划")
    @DeleteMapping("{id}")
    public  ResponseResult deleteNursingPlan(@PathVariable Integer id){
            nursingPlanService.deleteNursingPlan(id);
        return success();
    }
    @ApiOperation("启用禁用修改")
    @PutMapping("{id}/status/{status}")
    public ResponseResult updateStatus(@ApiParam(value = "护理计划Id", required = true)
                                       @PathVariable Integer id,
                                       @ApiParam(value = "要修改后的状态", required = true)
                                       @PathVariable Integer status) {

        nursingPlanService.updateStatus(id,status);
        return success();
    }
}

